﻿using Exiled.API.Features;
using Exiled.Events.EventArgs.Player;
using Exiled.Events.EventArgs.Server;
using PlayerStatsSystem;
using Exiled.Events.EventArgs.Scp079;
using Exiled.Events.EventArgs.Scp049;
using CustomPlayerEffects;
using RgCore.RoleAssignment;
using RgCore.Misc;

namespace TaskSystem
{
    public static class Tasks
    {
        #region 每日

        [EventSubscriber(nameof(RoundEndedEventArgs))]
        public static readonly Task GoodHabit = new Task("GoodHabit", "好习惯", "游玩一整个回合", 10, 100, false, 1, (e, player) =>
                                e is RoundEndedEventArgs && RoleAssignment.StartPlayer.Contains(player));

        [EventSubscriber(nameof(UsedItemEventArgs))]
        public static readonly Task Drugs = new Task("Drugs", "药瘾", "使用一瓶SCP-500", 5, 100, false, 1, (e, player) =>
                                 e is UsedItemEventArgs ev && ev.Player == player && ev.Item.Base.ItemTypeId == ItemType.SCP500);

        [EventSubscriber(nameof(DyingEventArgs))]
        public static readonly Task Timing = new Task("Timing", "Timing侠", "作为人形，使用武器杀死一名正在换弹的角色", 10, 200, false, 1, (e, player) =>
                                e is DyingEventArgs ev && ev.DamageHandler.Base is FirearmDamageHandler && ev.Attacker == player && ev.Player.IsReloading);

        [EventSubscriber(nameof(DiedEventArgs))]
        public static readonly Task DemoMan = new Task("DemoMan", "爆破手", "使用手雷杀死一名玩家", 5, 200, false, 1, (e, player) =>
                                 e is DiedEventArgs ev && ev.DamageHandler.Base is ExplosionDamageHandler && ev.Attacker == player && ev.Player != player);

        [EventSubscriber(nameof(EscapingEventArgs))]
        public static readonly Task Freedom = new Task("Freedom", "自由", "逃离设施", 10, 200, false, 1, (e, player) =>
                                 e is EscapingEventArgs ev && ev.Player == player && ev.IsAllowed);

        [EventSubscriber(nameof(EscapingPocketDimensionEventArgs))]
        public static readonly Task LadyLuck = new Task("LadyLuck", "幸运女神", "逃出口袋空间", 10, 200, false, 1, (e, player) =>
                                e is EscapingPocketDimensionEventArgs ev && ev.Player == player);

        [EventSubscriber(nameof(DiedEventArgs))]
        public static readonly Task FirearmYes = new Task("FirearmYes", "弃文从武", "作为科学家，杀死一名D级人员", 3, 200, false, 1, (e, player) =>
                                 e is DiedEventArgs ev && ev.Attacker == player && ev.TargetOldRole == PlayerRoles.RoleTypeId.ClassD && ev.Attacker?.Role.Type == PlayerRoles.RoleTypeId.Scientist);

        #endregion 每日

        #region 每周

        [EventSubscriber(nameof(DiedEventArgs))]
        public static readonly Task Container = new Task("Container", "收容者", "收容一名SCP", 20, 200, true, 1, (e, player) =>
                                e is DiedEventArgs ev && ev.DamageHandler.Base is AttackerDamageHandler adh && ev.Attacker == player && !adh.IsSuicide && ev.TargetOldRole.ToSpawnTeam() == RoleAssignment.SpawnTeam.SCPs);

        [EventSubscriber(nameof(RoundEndedEventArgs))]
        public static readonly Task Survivor = new Task("Survivor", "幸存者", "全局存活", 10, 200, true, 1, (e, player) =>
                                 e is RoundEndedEventArgs && ScoreMvpHandler.KeepAlive.Contains(player));

        [EventSubscriber(nameof(EscapingEventArgs))]
        public static readonly Task Rebellion = new Task("Rebellion", "叛变", "作为科学家被绑逃出", 10, 200, true, 1, (e, player) =>
                                  e is EscapingEventArgs ev && ev.Player == player && ev.Player.Role.Type == PlayerRoles.RoleTypeId.Scientist && ev.Player.IsCuffed && ev.IsAllowed);

        [EventSubscriber(nameof(EscapingEventArgs))]
        public static readonly Task ParkourMaster = new Task("ParkourMaster", "跑酷大师", "在3分钟内逃离设施", 30, 500, true, 1, (e, player) =>
                                  e is EscapingEventArgs ev && ev.Player == player && ev.IsAllowed && Round.ElapsedTime.TotalMinutes <= 3);

        [EventSubscriber(nameof(GainingLevelEventArgs))]
        public static readonly Task IQ500 = new Task("IQ500", "高智商", "作为SCP-079，达到5级访问权限", 30, 500, true, 1, (e, player) =>
                                 e is GainingLevelEventArgs ev && ev.Player == player && ev.NewLevel == 5);

        [EventSubscriber(nameof(SendingCallEventArgs))]
        public static readonly Task Archbishop = new Task("Archbishop", "教主", "作为SCP-049，释放10次召唤", 20, 300, true, 10, (e, player) =>
                                e is SendingCallEventArgs ev && ev.Player == player);

        [EventSubscriber(nameof(DiedEventArgs))]
        public static readonly Task Butcher = new Task("Butcher", "屠夫", "杀死400人", 50, 2000, true, 400, (e, player) =>
                                e is DiedEventArgs ev && ev.DamageHandler.Base is AttackerDamageHandler adh && !adh.IsSuicide && ev.Attacker == player);

        [EventSubscriber(nameof(JumpingEventArgs))]
        public static readonly Task Bunny = new Task("Bunny", "兔子精", "跳跃1000次", 20, 400, true, 1000, (e, player) =>
                                e is JumpingEventArgs ev && ev.Player == player);

        [EventSubscriber(nameof(DiedEventArgs))]
        public static readonly Task Shocked = new Task("Shocked", "发生甚么事了！？", "杀死一名被致盲玩家", 10, 200, true, 1, (e, player) =>
                        e is DiedEventArgs ev && ev.DamageHandler.Base is AttackerDamageHandler adh && !adh.IsSuicide && ev.Attacker == player && ev.Player.IsEffectActive<Flashed>());

        [EventSubscriber(nameof(DiedEventArgs))]
        public static readonly Task LeeSin = new Task("LeeSin", "盲僧", "在致盲时杀死一名玩家", 30, 500, true, 1, (e, player) =>
                         e is DiedEventArgs ev && ev.DamageHandler.Base is AttackerDamageHandler adh && !adh.IsSuicide && ev.Attacker == player && ev.Attacker.IsEffectActive<Flashed>());

        [EventSubscriber(nameof(UsedItemEventArgs))]
        public static readonly Task FranticCocktail = new Task("FranticCocktail", "狂乱的鸡尾酒", "拥有3级SCP-207效果", 100, 500, true, 1, (e, player) =>
                        e is UsedItemEventArgs ev && ev.Player == player && ev.Player.GetEffectIntensity<Scp207>() == 3);

        [EventSubscriber(nameof(DiedEventArgs))]
        public static readonly Task CorrosiveAttack = new Task("CorrosiveAttack", "腐蚀打击", "在口袋空间内杀死一名玩家", 50, 500, true, 1, (e, player) =>
                                 e is DiedEventArgs ev && ev.DamageHandler.Base is AttackerDamageHandler adh && !adh.IsSuicide && ev.Attacker == player && ev.Attacker.IsEffectActive<PocketCorroding>());

        #endregion 每周
    }
}